package smartq.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class Customers {
	
	public Customers() {
		CustomerPhonenumber = CustomerFirstName = CustomerLastName = Customersex = CustomerClass = CustomerPercen  = "";
	 }	
    public Customers(
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            String CustomerPhonenumber,
            String CustomerFirstName,
            String CustomerLastName,
            String Customersex,
            String CustomerClass,
            String CustomerPercen,
            String CustomerNumJoin,
            String CustomerNumBook
            
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        this.CustomerPhonenumber 	= CustomerPhonenumber;
        this.CustomerFirstName 		= CustomerFirstName;
        this.CustomerLastName 		= CustomerLastName;
        this.Customersex 			= Customersex;
        this.CustomerClass 			= CustomerClass;
        this.CustomerPercen			= CustomerPercen;

    }
    //-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		CustomerPhonenumber,
    		CustomerFirstName,
    		CustomerLastName,
    		Customersex,
    		CustomerClass,
    		CustomerPercen;
            
    
	Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
   

    // -------------------- GET-SET -------------------------
    
 
	public String getOID() {
		return OID;
	}
	
	public String getCustomerPercen() {
		return CustomerPercen;
	}
	public void setCustomerPercen(String customerPercen) {
		CustomerPercen = customerPercen;
	}
	public void setOID(String oID) {
		OID = oID;
	}
	public String getUsrOpt() {
		return UsrOpt;
	}
	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}
	public String getIsActive() {
		return IsActive;
	}
	public void setIsActive(String isActive) {
		IsActive = isActive;
	}
	public String getIsDeleted() {
		return IsDeleted;
	}
	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}
	public String getCustomerPhonenumber() {
		return CustomerPhonenumber;
	}
	public void setCustomerPhonenumber(String customerPhonenumber) {
		CustomerPhonenumber = customerPhonenumber;
	}
	public String getCustomerFirstName() {
		return CustomerFirstName;
	}
	public void setCustomerFirstName(String customerFirstName) {
		CustomerFirstName = customerFirstName;
	}
	public String getCustomerLastName() {
		return CustomerLastName;
	}
	public void setCustomerLastName(String customerLastName) {
		CustomerLastName = customerLastName;
	}
	public String getCustomersex() {
		return Customersex;
	}
	public void setCustomersex(String customersex) {
		Customersex = customersex;
	}
	public String getCustomerClass() {
		return CustomerClass;
	}
	public void setCustomerClass(String customerClass) {
		CustomerClass = customerClass;
	}

	//-------------------- SQL ------------------------
    public ResultSet selectCustomers(String StrClassSearch,String StrSexSeach,String CustomernameSearch) throws Exception {
        String StrSql = "SELECT [OID],"
                + "[LastModified],"
                + "[ModifiedDate],"
                + "[ModifiedTime],"
                + "[ModifiedBy],"
                + "[UserModified],"
                + "[CreatDate],"
                + "[CreatTime],"
                + "[CreatedBy],"
                + "[UserCreate],"
                + "[IsActive],"
                + "[IsDeleted],"
                
                + "[CustomerPhonenumber],"
                + "[CustomerFirstName],"
                + "[CustomerLastName],"
                + "[Customersex],"
                + "[CustomerClass],"
                + "[CustomerPercen] "
                
  				+ "FROM [Project_NFC].[dbo].[udfCustomers]() "
  
                + "WHERE [IsDeleted]='0' "; 

        
        if (!StrClassSearch.equals("")) {
            StrSql += " AND [CustomerClass] LIKE '%" + StrClassSearch + "%' ";
        }
        
        if (!StrSexSeach.equals("")) {
            StrSql += " AND [Customersex] LIKE '%" + StrSexSeach + "%' ";
        }

        if (!CustomernameSearch.equals("")) {
            StrSql += " AND [CustomerFirstName] LIKE '%" + CustomernameSearch + "%' OR [CustomerPhonenumber] LIKE '%" + CustomernameSearch + "%' " ;
        }

        //return sqlsel.getReSultSQL(StrSql);
        return con.selectData(StrSql);
    }

   

    public String OperationData(String OperationType) throws Exception {
        try {
        		conn = con.Connect();
                java.sql.CallableStatement cstmt = conn.prepareCall("{call stpCustomersManagement(?,?,?,?,? ,?,?,?,?,? ,?,?)}");
                
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getCustomerPhonenumber());
                cstmt.setString(7, getCustomerFirstName());
                cstmt.setString(8, getCustomerLastName());
                cstmt.setString(9, getCustomersex());
                cstmt.setString(10, getCustomerClass());
                cstmt.setString(11, getCustomerPercen());
                
                cstmt.registerOutParameter(12, Types.VARCHAR);
                cstmt.execute();
                return cstmt.getString(12);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    }
}
